<script setup lang="ts">
import { reactive, ref } from "vue";
import { putOneCompeteAPI } from "@/api/resource.ts";
import { ElMessage } from "element-plus";

const dialogVisible = ref(false)
const idValue = ref()
const form = reactive({
  name: '',
  phone: '',
  value: ''
})

const init = (id: string) => {
  idValue.value = id
  dialogVisible.value = true
}

// 录入第一名
const addOne = async () => {
  const res = await putOneCompeteAPI(idValue.value, form)
  ElMessage({
    type: res.code === 0 ? 'success' : 'error',
    message: res.message
  })
  dialogVisible.value = false
}

defineExpose({
  init
})
</script>

<template>
  <el-dialog v-model="dialogVisible" title="成绩录入" width="40%">
    <el-form
      ref="ruleFormRef"
      style="max-width: 600px"
      :model="form"
      label-width="auto"
      class="demo-ruleForm"
      status-icon
    >
      <el-form-item prop="name" label="用户名">
        <el-input v-model="form.name"/>
      </el-form-item>
      <el-form-item prop="phone" label="手机号">
        <el-input v-model="form.phone"/>
      </el-form-item>
      <el-form-item prop="value" label="成绩">
        <el-input v-model="form.value"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="addOne">确认</el-button>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">
.list {
  display: flex;
  flex-direction: column;

  .item {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin: 0 20px 20px 0;

    span {
      width: 80px;
    }

    .el-input {
      width: 350px;
    }
  }
}
</style>
